Main site

Sample codes > Sample vendor - AliExpress

Sample vendor - AliExpress

As with any LLM AI model outputs, always verify the generated code for accuracy before deploying it live.

For the sample prompts here, your might get different responses since AI models have random elements.

AI Prompt:

I'd like a shipping rate calculator for items from AliExpress products.
The AliExpress product id is contained as part of the items sku separated with a hyphen. Split the sku and take the first part as AliExpress product id.

AI Output:

import { enrichItemDetails } from "./modules.js";
import { AliExpress } from "./modules.js";

export async function calculateShippingRates(DATA, env) {
  try {
    // Enrich item details with additional fields
    DATA = await enrichItemDetails(DATA);

    // Extract AliExpress product ids from item skus
    const aliexpressProducts = DATA.items.map((item) => {
      const [aliexpressProductId] = item.sku.split("-");
      return { aliexpress_product_id: aliexpressProductId, quantity: item.quantity };
    });

    // Initialize AliExpress instance with destination and currency
    const aliexpress = new AliExpress(DATA.destination, DATA.currency);

    // Get shipping rates from AliExpress
    const rates = await aliexpress.getRates(aliexpressProducts);

    // Return shipping rates in Shopify format
    return { rates };
  } catch (error) {
    // Return error rate
    return {
      rates: [
        {
          service_name: "Error",
          service_code: "error",
          total_price: null,
          description: error.message,
          currency: DATA.currency,
          min_delivery_date: "",
          max_delivery_date: "",
        },
      ],
    };
  }
}